package com.example.hasee.intenttest2;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.PhoneNumberUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class IntentTest2 extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_intent_test2);
        final EditText phoneNum = (EditText)findViewById(R.id.phoneNum);
        final Button button = (Button)findViewById(R.id.B1);
        button.setOnClickListener(new Button.OnClickListener(){
            public void onClick(View b){
                //Intent <Intent_name>=new Intent (<Action>,<Data>);
                String call = phoneNum.getText().toString();
                if (PhoneNumberUtils.isGlobalPhoneNumber(call)){
                    Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel://" + call));
                    //Intent intent = new Intent(Intent.ACTION_DIAL,Uri.parse(tel"://"+call))
                    startActivity(intent);
                }else {
                    Toast.makeText(IntentTest2.this,"您输入的号码不正确，请重新输入",Toast.LENGTH_SHORT).show();
                }
            }


        });
    }
}
